package com.woniu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.domain.Classify;
import com.woniu.mapper.ClassifyMapper;
import com.woniu.mapper.PositionAndCompanyMapper;
import com.woniu.mapper.PositionMapper;
import com.woniu.service.PositionAndCompanyService;
import com.woniu.vo.*;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;

@Service
public class PositionAndCompanyServiceImpl extends ServiceImpl<PositionAndCompanyMapper, PositionAndCompany>implements PositionAndCompanyService {

    @Resource
    private PositionAndCompanyMapper positionAndCompanyMapper;
    @Resource
    private ClassifyMapper classifyMapper;
    @Resource
    private PositionMapper positionMapper;

    @Override
    public IPage<PositionAndCompany> getPositionAndCompany(LikePositionVo likePositionVo) {
        Page<PositionAndCompany> page=new Page<PositionAndCompany>(likePositionVo.getCurrent(),likePositionVo.getSize());
        //考略的条件有：根据vo去查出二级分类id
        //考略的公司该公司的状态必须为“已通过”
        //考略职位状态位“发布”
        QueryWrapper<Classify> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("level",2);
        queryWrapper.eq("name",likePositionVo.getSecondename());
        System.out.println("likePositionVo.getSecondename------------------"+likePositionVo.getSecondename());
        Classify classify = classifyMapper.selectOne(queryWrapper);
        QueryWrapper<PositionAndCompany> ew = new QueryWrapper<PositionAndCompany>();
        boolean b=true;

        if(b&&!ObjectUtils.isEmpty(classify)){
            ew.eq("second_cid",classify.getId());
            b=false;
        }
        if(b&&!ObjectUtils.isEmpty(likePositionVo.getSecondename())){
            ew.like("tname",likePositionVo.getSecondename());
        }
        ew.eq("c.status","已通过");
        ew.eq("p.statusc","发布");
        if(ObjectUtils.isEmpty(likePositionVo.getSecondename())&&ObjectUtils.isEmpty(classify)){
            return null;
        }
        IPage<PositionAndCompany> positionAndCompany= positionAndCompanyMapper.getPositionAndCompany(page, ew);
        return positionAndCompany;

    }

}
